﻿<form action="index.php" method="post" name="addFrom" >
<table>
	<tr style="border:1px solid silver">
		<td colspan="2" style="background:silver;"><h4><?php echo (isset($this->item->id)?'Cập nhật thông tin sản phẩm':'Thêm sản phẩm') ?></h4></td>
	</tr>
	<tr style="border:1px solid silver">
		<td>Tên sản phẩm</td>
		<td>
			<input type="text" style="width:260px;" name="productname" value="<?php echo (isset($_POST['productname']))?$_POST['productname']:@$this->item->productname ?>" />		
		</td>
	</tr>
	<tr style="border:1px solid silver">
		<td>Giá</td>
		<td>
			<input type="text" style="width:260px;" name="price" value="<?php echo (isset($_POST['price']))?$_POST['price']:@$this->item->price ?>" />(VND)		
		</td>
	</tr>
	<tr style="border:1px solid silver">
		<td>Mô tả</td>
		<td>
			<textarea rows="7" cols="50" name="description"><?php echo (isset($_POST['description']))?$_POST['description']:@$this->item->description ?></textarea>	
		</td>
	</tr>
	<tr style="border:1px solid silver">
		<td>ID bài viết bảng giá</td>
		<td>
			<input type="text" style="width:100px;" name="pricetable" value="<?php echo (isset($_POST['pricetable']))?$_POST['pricetable']:@$this->item->pricetable ?>" />		
		</td>
	</tr>
	<tr style="border:1px solid silver">
		<td>Loại xe</td>
		<td>
			<select onChange="submitcat();" name="catid" >
			<?php foreach($this->cat as $cat){ ?>
				<?php if((@$cat->id==@$this->item->catid&&!isset($_POST['catid']))||(@$cat->id==@$_POST['catid'])&&isset($_POST['catid'])){ ?>
					<option  value="<?php echo $cat->id ?>" selected ><?php echo $cat->name ?></option>
				<?php }else{ ?>
					<option value="<?php echo $cat->id ?>"><?php echo $cat->name ?></option>
			<?php }}?>	
			</select>		
		</td>
	</tr>
	<tr style="border:1px solid silver">
		<td>Model</td>
		<td>
			<select onChange="submitcat();" name="mode" >
			<?php foreach($this->model1 as $model){ ?>
				<?php if((@$model->id==@$this->item->mode&&!isset($_POST['mode']))||(@$model->id==@$_POST['mode'])&&isset($_POST['mode'])){ ?>
					<option  value="<?php echo $model->id ?>" selected ><?php echo $model->name ?></option>
				<?php }else{ ?>
					<option value="<?php echo $model->id ?>"><?php echo $model->name ?></option>
			<?php }}?>	
			</select>		
		</td>
	</tr>
	<?php if(is_array(@$this->attri)){ ?>
		<?php foreach($this->attri as $attri){ ?>
			<tr style="border:1px solid silver">
				<td><?php echo @$attri->name ?></td>
				<td>
					<input type="hidden" name="idattri[]" value="<?php echo @$attri->id?>" />
					<input type="text" style="width:260px;" name="attrivalue[]" value="<?php echo @$this->model->getAttriValue(@$attri->id,@$this->item->id) ?>" />		
				</td>
			</tr>
		<?php } ?>
	<?php }?>
	<tr>
		<td>
			Xuất bản
		</td>
		<td colspan="2">Có <input type="radio" <?php echo (@$this->item->published==1)?'checked':''; ?> name="published" <?php echo (!isset($this->item->published))?'checked':''; ?> value="1" /> Không <input name="published" type="radio"  <?php echo (@$this->item->published==0)?'checked':''; ?> value="0" /></td>
	</tr>
	<tr>
		<td>
			<input type="submit" value="Save" />
			<input type="button" onclick="document.location.href='index.php?c=product';" value="Close" />
		</td>
	</tr>
</table>
<input type="hidden" name="c" value="product" />
<input type="hidden" name="t" value="proccessadd" />
<input type="hidden" name="id" value="<?php echo @(int)$this->item->id ?>" />
</form>
<script type="text/javascript">
	function checkvalid()
	{
		if(document.addFrom.name.value=='')
			alert('Vui lòng nhập tên !');
		else
			document.addFrom.submit();
	}
	
	function submitcat()
	{
		document.addFrom.t.value='add';
		document.addFrom.submit();
	}
</script>
